<?PHP
// digiboard by digitalboom.org
// http://www.digitalboom.org
//
// Information Technology program
// Sirindhorn International Institute of Technology
// Thammasat University, Rangsit Campus
// http://www.siit.tu.ac.th
//
// first created on: 2004 June 9
// last modified on: 2008 Feb 15
// Last modified by: BiGGA

include_once("settings/spam.inc.php");

function is_spam($msgdetail) {
  global $DGB;
  $ret = false;
  $ratio = 0;

  // add/modify spam terms/sites in settings/spam.inc.php
  $keyword = $DGB["SPAM_TERMS"];
  $spamsite = $DGB["SPAM_SITES"];
  
  $exclam = substr_count($msgdetail, "!");
  //$question = substr_count($msgdetail, "?");
  //$dot = substr_count($msgdetail, ".");
  $hat = substr_count($msgdetail, "^");
  $star = substr_count($msgdetail, "*");
  
//Fucking foreign spam
  $username = 
  $http = substr_count($msgdetail, "http://");
  $num_new_lines = substr_count($msgdetail, "\n");
  $num_thank = substr_count($msgdetail, "thank");
  $num_Thank = substr_count($msgdetail, "Thank");
  $num_site = substr_count($msgdetail, "site");

  $symbol = $exclam + $question + $hat + $star;

  $len = strlen($msgdetail);
 
  foreach ($keyword as $key) {
    if (in_str($msgdetail, $key)) {
      $symbol += 10; 
    }
  }

  if ($symbol > 0) { 	
    $ratio = ($symbol / $len) * 100;
  }

  if ($ratio >> 15.0) {
	$ret=true;
  }

  //Get rid of foreigner spam
  //Pattern of the spam is, he thanks us.
  //and there is nothing much but the http links.
  //However, the num link and num line is pretty much the same.
  
  //Better ceterion to filter is number of same words per line.
  //The URL name contains the same words as the comment after the URL.
  //For instance, http://fucking.spam.xxx.yyy.com fucking spam
  //See, the domain name and the comment after the URL are the same
  //Will implment this soon. 

  $http_newline = $num_new_lines - $http;
  $num_thank += $num_Thank;
  if($num_thank == 1 && $num_site > 0){
    $thankme = true;
  }

  if ($http > 4 && ($http_newline == 0 || $http_newline == 1 || $http_newline == -1)){
//  if ($http > 4 && $thankme){
    $ret = true;
  }

  foreach ($spamsite as $site) {
    if(in_str($msgdetail, $site)) {
      $ret = true; 
    }
  }
  return $ret;
}

//Check if the poster is spammer
function is_spammer($msgby,$icq) {
  global $DGB;
  $ret = false;
  $has_icq = false;
  $msgby_spammer = $DGB["SPAM_SPAMMERS"];
  
  foreach ($msgby_spammer as $key) {
    if (in_str($msgby, $key)) {
      $ret = true; 
    }
  }
  
  if ($icq != ""){
	  $ret = true; 
  }
  
  return $ret;
}

// bool in_str(string haystack, string needle)
function in_str($haystack,$needle) {
 $re = stristr($haystack,$needle);
 return ( (boolean) $re);
}

?>
